
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template_padrao.xhtml">

	<ui:define name="content">

		<h2>Cadastro de Consumo</h2>
		<h:form id="form_cad_consumo">

		<p:fieldset styleClass="fieldsetPadrao">
					<legend>Pesquisa</legend>
					
					<table>
						<tr>
							<td><h:outputLabel value="Obra" /> </td>
							<td><p:selectOneMenu value="#{consumoMB.obraSelecionada}">
										<f:selectItems value="#{consumoMB.listaObras}" />
								</p:selectOneMenu></td>
						</tr>
						
						<tr>
							<td><h:outputLabel value="Material"/> </td>
							<td><p:inputText value="#{consumoMB.materialPesquisa}" /></td>
						</tr>
						
						<tr>			
							<td><p:commandButton value="Buscar"	
												 action="#{consumoMB.pesquisarMaterial()}" 
												 ajax="false" 
												 update=":form_cad_consumo:table_list_itens_consumo" /></td>
							
						</tr>
					</table>
			</p:fieldset>
			
			<br />

			<h:panelGroup id="pnl_list_materiais" rendered="#{consumoMB.listaFornecedorMaterial != null}">
				<h3>Lista Materiais</h3>
				
				<p:dataTable value="#{consumoMB.listaFornecedorMaterial}" 
							 var="fornecedor" 
							 id="table_list_forn_materiais" 
							 rendered="#{consumoMB.listaFornecedorMaterial != null}">
					
					<p:column style="width: 260px;">
						<f:facet name="header">
							<h:outputText value="Fornecedor" />
						</f:facet>
						<h:outputText value="#{fornecedor.pessoaJuridica.nomeFantasia}" />
					</p:column>
	
					<p:column style="width: 260px;">
						<f:facet name="header">
							<h:outputText value="Descrição" />
						</f:facet>
						<h:outputText value="#{fornecedor.material.descricaoMaterial}" />
					</p:column>
					
					<p:column style="width: 40px;">
						<f:facet name="header">
							<h:outputText value="Qtd." />
						</f:facet>
						<h:inputText value="#{fornecedor.qtdSolicitada}" size="6" />
					</p:column>
					
					<p:column style="width: 150px;">
						<f:facet name="header">
							<h:outputText value="Preço" />
						</f:facet>
						<h:outputText value="#{fornecedor.valor}" >
							<f:convertNumber currencySymbol="R$" type="currency" />
						</h:outputText>
					</p:column>
	
					<p:column>
						<f:facet name="header">
							<h:outputText value="Incluir" />
						</f:facet>
						<p:commandLink update=":form_cad_consumo:bt_group_salvar_cancel, 
												:form_cad_consumo:panelGroup_table_list_itens_consumo" 
										actionListener="#{consumoMB.adicionaItemListaConsumo(fornecedor)}" 
										value="Adicionar"/>
					</p:column>
	
				</p:dataTable>
			</h:panelGroup>

			
			<h:panelGroup id="panelGroup_table_list_itens_consumo" layout="block">
				<br />
				<h3><h:outputText value="Itens do pedido"  rendered="#{consumoMB.listaItensConsumidos.size() > 0}" /></h3>
				<p:dataTable value="#{consumoMB.listaItensConsumidos}" 
							 var="consumo" 
							 paginator="true" 
							 paginatorPosition="bottom" 
							 id="table_list_itens_consumo" 
							 rendered="#{consumoMB.listaItensConsumidos.size() > 0}">
						
				<p:column style="width: 260px;">
					<f:facet name="header">
						<h:outputText value="Fornecedor" />
					</f:facet>
					<h:outputText  value="#{consumo.pessoaJuridica.nomeFantasia}"  />
				</p:column>

				<p:column style="width: 260px;">
					<f:facet name="header">
						<h:outputText value="Descrição" />
					</f:facet>
					<h:outputText value="#{consumo.material.descricaoMaterial}" />
				</p:column>


				<p:column style="width: 40px;">
					<f:facet name="header">
						<h:outputText value="Qtd." />
					</f:facet>
					<h:inputText value="#{consumo.qtdSolicitada}" disabled="true" size="6" />
				</p:column>
				
				<p:column style="width: 150px;">
					<f:facet name="header">
						<h:outputText value="Preço Total" />
					</f:facet>
					<h:outputText value="#{consumo.valorTotalPorMaterial}" >
						<f:convertNumber currencySymbol="R$" type="currency"/>
					</h:outputText>
				</p:column>
				
				<p:column>
					<f:facet name="header">
						<h:outputText value="Remover" />
					</f:facet>

					<p:commandLink 	update=":form_cad_consumo:bt_group_salvar_cancel, 
									:form_cad_consumo:panelGroup_table_list_itens_consumo" 
									actionListener="#{consumoMB.adicionaItemListaConsumo(consumo)}" 
									value="Remover"  
									disabled="#{!consumo.edicao}"/>
				
				 <f:facet name="footer">  
            		Total R$: <h:outputText value="#{consumoMB.valorTotalConsumoCadastrado}" />
        		</f:facet> 
				</p:column>
				
				</p:dataTable>
				
				
			</h:panelGroup>

			<br />

			<h:panelGroup id="bt_group_salvar_cancel">
				<p:commandButton action="#{consumoMB.salvar()}" 
								value="Salvar" 
								id="bt_salvar"	
								ajax="false" 
								rendered="#{consumoMB.listaItensConsumidos.size() > 0}"/>
								
				<p:commandButton action="#{consumoMB.cancelar()}" 
								value="Cancelar"
								id="bt_cancelar" 
								ajax="false" />
			</h:panelGroup>

		</h:form>


	</ui:define>

</ui:composition>

</html>